package mobi.yuanshen.service.impl;

import lombok.extern.slf4j.Slf4j;
import mobi.yuanshen.service.UploadService;
import mobi.yuanshen.utils.FileTransforServer;
import mobi.yuanshen.utils.ParamsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@Service
public class UploadServiceImpl implements UploadService {

    @Autowired
    FileTransforServer fileTransforServer;

    @Autowired
    ParamsUtils paramsUtils;

    @Override
    public String uploadFile(MultipartFile file) throws IOException {
        String fileName = fileTransforServer.transToServer(
                null,
                file,
                file.getOriginalFilename());
        String url = paramsUtils.FileStorageHttpPath + "/" + fileName;
        log.info("存储成功,访问url:{}", url);
        return url;
    }
}
